#include "../UnitTest.h"

char codigo_encriptado[500];

void
unit_test_1(void)
{
	char Man[10];
        char Buffer[5];
        int i = 0;
	int aux;
        char* text = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
	memset(codigo_encriptado,'\0', sizeof(char)*500);      

        for(i = 0; i< 10; i++)
                Man[i]='\0';

	aux = strlen(text);
	aux =(int)aux/3;
	
	printf("\n\nPrueba_1:\n");
        printf("---------\n");
	for(i = 0; i < aux; i++){
                strncpy(Man,text,3);
                text++;
                text++;
                text++;
                b64_encode(Buffer, Man);
                printf("%s ", Buffer);
		strcat(codigo_encriptado, Buffer);
        }

	strncpy(Man,text,3);
 	b64_encode(Buffer, Man);      
        printf("%s ", Buffer);
	strcat(codigo_encriptado, Buffer);

}

void
unit_test_2(void)
{
	int i = 0;
	int aux = 0;
	char Man[10];
        char Buffer[5];
	char *p = codigo_encriptado;
	aux = strlen(p);
	
	printf("\n\nPrueba_2:\n");
        printf("---------\n");
	printf("Desencriptacion\n");
	for(i = 0; i < aux; i +=4)
	{
		strncpy(Man, p, 4);
		p+= 4;
		b64_decode(Buffer, Man);
		printf("%s", Buffer);
	}

}

void
unit_test_3(void)
{
	char Man[10];
        char Buffer[5];
	printf("\n\nPrueba_3:\n");
	printf("---------\n");
        
	printf("Codificacion\n");
	strcpy(Man,"e.");
	b64_encode(Buffer, Man);
	printf("e. --> encode --> %s \n", Buffer);        

        strcpy(Man,"e");
        b64_encode(Buffer, Man);
	printf("e --> encode --> %s \n", Buffer);

        printf("Decodificacion\n");
        strcpy(Man,"ZS4=");
        b64_decode(Buffer, Man);
        printf("ZS4= --> decode --> %s \n", Buffer);
        
        strcpy(Man,"ZQ==");
        b64_decode(Buffer, Man);
        printf("ZQ== --> decode --> %s \n", Buffer);

	printf("Provocar errores\n");
	printf("1_ Se intenta pasar un codigo invalido con el siguiente caracter '?'\n");
	strcpy(Man,"Z?==");
        if(b64_decode(Buffer, Man) == B64_CHARACTER_INVAL)
        	printf("Caracter invalido\n");

	printf("2_ Se intenta pasar una cadena mas larga de lo establecido, con un tamanio de 5\n");
        strcpy(Man,"ZQP==");
        if(b64_decode(Buffer, Man) == B64_LENGTH_INVAL)
                printf("Cadena invalida\n");


}


